﻿using System.Collections.Specialized;
using DBFile.Core.Interfaces;
using DBFile.Providers.Impl;

namespace DBFile.Providers
{
    public class WcfFileProvider : DBFileProviderBase
    {
        protected override string ProviderDescription
        {
            get { return ProviderDescriptionMessage; }
        }
 
        protected override void OnAfterInitialize(NameValueCollection config)
        {
            this.EndpointConfigurationName = GetConfigSettingOrThrow(config, EndpointConfigurationNameKey,
                EndpointConfigurationMissingMessage);
        }

        protected override IDBFileProvider Provider
        {
            get
            {
                lock (padLock)
                {
                    if (_provider == null)
                    {
                        _provider = new WcfClient(EndpointConfigurationName);
                    }
                }
                return _provider;
            }
        }

        internal string EndpointConfigurationName { get; set; }

        private const string ProviderDescriptionMessage = "Wcf DBFile Provider";
        private const string EndpointConfigurationNameKey = "endpointConfigurationName";
        private const string EndpointConfigurationMissingMessage = "Endpoint configuration name is not specified";
    }
}
